package com.qf.t1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

/*
杨威
2021/9/4
9:31
*/
public class Demo {

    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");
        Connection root = DriverManager.getConnection("jdbc:mysql://localhost:3306/schools?useSSL=false&character=utf-8", "root", "1234");



        Scanner sca = new Scanner(System.in);
        System.out.println("请选择你想要修改的内容:");
        System.out.println("1:姓名  2：性别  3：电话号  ");
        System.out.println("4：邮箱  5：家庭住址 6：班级 " );
        int a = sca.nextInt();
        switch (a){
            case 1 :
                PreparedStatement preparedStatement = root.prepareStatement("update student set stuname = ? where stuid =?;");
                System.out.println("请输入你想要修改的学生id");
                int i2 = sca.nextInt();
                preparedStatement.setInt(2, i2);
                System.out.println("请输入你想要修改的内容");
                String str = sca.nextLine();

                preparedStatement.setString(1, str);

                int i = preparedStatement.executeUpdate();
                if(i>0){
                    System.out.println("修改成功");
                }else{
                    System.out.println("修改失败");
                }
                preparedStatement.close();
                root.close();
                break;
            case 2:
                PreparedStatement preparedStatement1 = root.prepareStatement("update student set stuGender = ? where stuid =?;");
                System.out.println("请输入你想要修改的内容");
                String str1 = sca.nextLine();

                System.out.println("====================================================");
                System.out.println("请输入你想要修改的学生id");
                int i3 = sca.nextInt();
                preparedStatement1.setString(1, str1);
                preparedStatement1.setInt(2, i3);
                int i1 = preparedStatement1.executeUpdate();
                if(i1>0){
                    System.out.println("修改成功");
                }else{
                    System.out.println("修改失败");
                }
                preparedStatement1.close();
                root.close();
                break;
            case 3:
                System.out.println("请输入你想要修改的学生id");
                int i4 = sca.nextInt();
                System.out.println("请输入你想要修改的内容");
                String str2 = sca.nextLine();
                PreparedStatement preparedStatement2 = root.prepareStatement("update student set stuGender = ? where stuid =?;");
                preparedStatement2.setString(1, str2);
                preparedStatement2.setInt(2, i4);
                int ii = preparedStatement2.executeUpdate();
                if(ii>0){
                    System.out.println("修改成功");
                }else{
                    System.out.println("修改失败");
                }
                preparedStatement2.close();
                root.close();
                break;
            case 4:
                System.out.println("请输入你想要修改的学生id");
                int i5 = sca.nextInt();
                System.out.println("请输入你想要修改的内容");
                String str3 = sca.nextLine();
                PreparedStatement preparedStatement3 = root.prepareStatement("update student set stuGender = ? where stuid =?;");
                preparedStatement3.setString(1, str3);
                preparedStatement3.setInt(2, i5);
                int ii1 = preparedStatement3.executeUpdate();
                if(ii1>0){
                    System.out.println("修改成功");
                }else{
                    System.out.println("修改失败");
                }
                preparedStatement3.close();
                root.close();
                break;
            case 5:
                System.out.println("请输入你想要修改的学生id");
                int i6 = sca.nextInt();
                System.out.println("请输入你想要修改的内容");
                String str4 = sca.nextLine();
                PreparedStatement preparedStatement4 = root.prepareStatement("update student set stuGender = ? where stuid =?;");
                preparedStatement4.setString(1, str4);
                preparedStatement4.setInt(2, i6);
                int ii2 = preparedStatement4.executeUpdate();
                if(ii2>0){
                    System.out.println("修改成功");
                }else{
                    System.out.println("修改失败");
                }
                preparedStatement4.close();
                root.close();
                break;
            case 6:
                System.out.println("请输入你想要修改的学生id");
                int i7 = sca.nextInt();
                System.out.println("请输入你想要修改的内容");
                String str5 = sca.nextLine();
                PreparedStatement preparedStatement5 = root.prepareStatement("update student set stuGender = ? where stuid =?;");
                preparedStatement5.setString(1, str5);
                preparedStatement5.setInt(2, i7);
                int ii3 = preparedStatement5.executeUpdate();
                if(ii3>0){
                    System.out.println("修改成功");
                }else{
                    System.out.println("修改失败");
                }
                preparedStatement5.close();
                root.close();
                break;
        }





    }

}

